package com.naiterui.ehp.bs.ds.modules.sys.utils;

import java.util.List;

import com.google.common.base.Preconditions;
import com.naiterui.ehp.bp.utils.context.SpringContextHolder;
import com.naiterui.ehp.bs.ds.modules.sys.service.IDictService;
import com.naiterui.ehp.bs.ds.modules.sys.vo.DictVO;

/**
 * 字典工具类
 */
public class DictUtil {

    private static final IDictService DICT_SERVICE = SpringContextHolder.getBean(IDictService.class);

    public static String getNameByTypeAndCode(String type, String code) {
        Preconditions.checkNotNull(type, "字典类型不能为null");
        Preconditions.checkNotNull(code, "字典编码不能为null");
        List<DictVO> list = DICT_SERVICE.queryVueList(type);
        for (DictVO dictVO : list) {
            if (dictVO.getCode().equals(code)) {
                return dictVO.getValue();
            }
        }
        return String.format("没有查询到此字典编码type: %s code: %s", type, code);
    }

}
